package javaweb_work01.classesContrl.Dao;

import javaweb_work01.classesContrl.Entity.Classes;
import javaweb_work01.login.Utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * 访问数据库实现添加新班级功能
 */
public class AddClassesDaoImp implements AddClassesDao{

    @Override
    public void addClasses(Classes classes) {
        try {
            //使用连接池创建QueryRunner对象
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            //编写sql语句
            String sql = "insert into class values(null,?,?,?,?)";
            //设置占位符参数
            Object[] param = {classes.getClass_name(),classes.getGrade(),classes.getTeacher(),classes.getWatchword()};
            //执行语句
            int update = qr.update(sql, param);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
